<template>
  <div class="about">
    <el-container>
      <!-- 头部搜索栏 -->

      <el-header class="outHeader">
        <el-row class="headerRow" type="flex">
          <el-col :span="2" :xs="4">
            <el-image :src="require('../assets/home/book.png')" class="mainImg"></el-image>
          </el-col>
          <el-col :span="8">
            <div @keyup.enter="doSearch" style="display:flex;flex-direction:row;" class="searchText">
              <el-input placeholder="搜寻你想要的书名" suffix-icon="el-icon-search" v-model="input">
              </el-input>
              <el-button type="info" plain @click="doSearch">查询</el-button>
            </div>
          </el-col>
        </el-row>
      </el-header>

      <!-- 主体内容区域 -->
      <el-main class="outMain">
        <div class="listDiv">
          <el-card class="outer-card">
            <div v-for="(book,index) in books" :key="index" class="text item">
              <el-card class="inner-card" shadow="never">
                <el-row type="flex" justify="space-around">
                  <el-col :span="6">
                    <el-image :src="require('@/assets/logo.png')" class="listImg"></el-image>
                  </el-col>
                  <el-col :span="16" class="content-col">
                    <el-row type="flex">
                      <el-col>
                        <el-link type="primary" :underline="false" class="nameLink" @click="toDetail(book,book.id)">
                          {{book.bookName}}
                        </el-link>
                        <!-- <span>{{book.name}}</span> -->
                      </el-col>
                    </el-row>
                    <el-row type="flex">
                      <el-col :span="16" :xs="24">
                        <span>作者：{{book.author}}</span>
                      </el-col>
                      <el-col :span="16" class="hidden-xs-only">
                        <span>出版时间：{{book.publishTime}}</span>
                      </el-col>
                    </el-row>
                    <el-row type="flex">
                      <el-col :span="11">
                        <span>价格：{{book.price}}</span>
                      </el-col>

                      <el-col :span="11">
                        <span>数量：{{book.quantity}}</span>
                      </el-col>
                    </el-row>
                    <el-row type="flex">
                      <el-col>
                        <span>出版商：{{book.publisher}}</span>
                      </el-col>
                    </el-row>
                    <el-row type="flex">
                      <el-col class="hidden-xs-only">
                        <span>ISBN：{{book.isbn}}</span>
                      </el-col>
                    </el-row>
                    <el-row type="flex" class="hidden-xs-only">
                      <el-col :span="24" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
                        书籍简介：{{book.description}}
                      </el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </el-card>


            </div>
          </el-card>


        </div>
      </el-main>

    </el-container>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    name: 'about',
    inject: ['reload'],
    data() {
      return {
        books: [],
        input: "",
      };
    },
    created: function () {
      this.input = this.$store.state.searchContent;
      this.getData(); // 在编译完成后初始化数据，然后让更新后的数据挂载即可
    },
    methods: {
      doSearch: function () {
        this.$store.commit('changeSearch', this.input);
        this.reload();
        // console.log("okkk");
      },
      // 获取符合条件的id
      getData() {
        let that = this;
        axios.get('http://localhost:8080/book/searchName', {
            params: {
              'bookName': that.input
            }
          })
          .then(function (response) {
            console.log(response.data);
            that.books = response.data;
          })
          .catch(function (err) {
            console.log(err)
          })
      },
      toDetail(book, bookID) {
        this.$router.push({
          name: "Detail",
          path: '/detail/:bookID',
          params: {
            bookID: bookID,
            inputTR: this.input,
            bookInfo: book,
          }
        });
      },

    }
  }
</script>

<style scoped>
  .el-card__body {
    padding: 2px;
  }

  /* .el-col {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  } */

  /* 导航部分 */
  .about {
    height: 100%;
  }

  .about>.el-container {
    height: 100%;
    background-color: #e2dfd7;
  }

  .outHeader {
    margin-bottom: 10px;
  }

  .mainImg {
    height: 50px;
    width: 50px;
  }

  .searchText {
    margin-top: 5px;
  }

  .headerRow {
    margin-top: 10px;
  }



  /* 内容部分 */
  .outMain {
    background-color: #f3ebe1;
    text-align: left;
    /* padding-left: 60px; */
    /* padding-right: 60px; */
    line-height: 1.7
  }

  .listDiv {
    max-width: 1000px;
  }

  ul {
    padding: 0px;
  }

  li {
    list-style-type: none
  }

  .listContainer {
    background-color: white;
  }

  .content-col {
    display: flex;
    flex-direction: column;
    justify-content: space-around;

  }

  .content-col .el-row .el-col {
    display: flex;
    width: 100%;
  }

  .innerHeader {
    max-height: 40px;
    padding-left: 0px;
    margin-bottom: 10px;
  }

  .innerMain {
    padding-top: 0px;
    padding-left: 0px;
  }

  .listImg {
    width: 100%;
    height: auto;
    max-width: 200px;
  }

  .innerHeaderRow {
    padding-top: 10px;
    font-size: 18px;
  }

  .bookInfoOne {
    font-size: 15px;
  }

  .innerHeaderRow /deep/ .el-link {
    font-size: 20px;
  }

  .innerHeader /deep/ .el-divider {
    margin: 0px;
    border-top: 1px dotted grey;
    background-color: white;
  }


  @media screen and (max-width:450px) {
    .outMain {
      font-size: 12px;
    }
  }

  @media screen and (min-width:1000px) {
    .outMain {
      padding-left: 80px;
      padding-top: 30px;
    }
  }
</style>

// 获取符合条件的id
getData() {
var bookss;
let that = this;
axios.get('../data.json').then(response => {
console.log(response.data);
that.books = response.data;
});
},

if (response.data.success == true) {
that.books = response.data.content
console.log(that.books)
} else {
alert("没找到！")
}